import { reqUserAddress, reqOrderInfo, reqSubmitOrder } from "@/api"
export default {
    namespaced: true,
    actions: {
        //获取用户地址信息
        async getAddress({ commit }) {
            let result = await reqUserAddress()
            if (result.code == 200) {
                commit("GETADDRESS", result.data)
            }
        },
        //获取用户交易商品信息
        async getOrderInfo({ commit }) {
            let result = await reqOrderInfo()
            console.log(result);
            if (result.code == 200) {
                commit("GETORDERINFO", result.data)
            }
        },
        //提交订单信息
        async getSubmitOrder({ commit }, data) {
            //结构data里面的参数
            let { tradeNo } = data;
            let { itemInfo } = data;
            let result = await reqSubmitOrder(tradeNo, itemInfo)
            if (result.code == 200) {
                return result;
            } else {
                return Promise.reject(result.message)
            }
        },
    },
    mutations: {
        GETADDRESS(state, address) {
            state.userAddress = address
        },
        GETORDERINFO(state, orderInfo) {
            state.orderInfo = orderInfo
        }
    },
    state: {
        userAddress: [],
        orderInfo: {}
    },
    getters: {}
}